package study.translation.grammar;

import java.util.HashSet;
import java.util.Set;

public class Nonterminal extends Symbol
{
    private Set<Rule> rules = new HashSet<Rule>();

    private Rule emptyRule = null;

    public Nonterminal( String name )
    {
        super( name );
    }

    public void addRule( Rule rule )
    {
        rules.add( rule );
        if( rule.isEmpty() )
        {
            emptyRule = rule;
        }
    }

    public Set<Rule> getRules()
    {
        return rules;
    }

    public boolean hasEmptyRule()
    {
        return ( null != emptyRule );
    }

    public String toString()
    {
        return "<" + getName() + ">";
    }
}
